package com.ke.jdyd.service;

import android.util.Log;
import com.ke.jdyd.http.BaseResponse;
import com.ke.jdyd.http.RetrofitFactory;
import com.ke.jdyd.model.GoodsEntity;
import com.ke.jdyd.model.GoodsInfo;

import java.util.List;

import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Url;

public class HomeSerivce {
  private HomeApi mApi;
  private static final String TAG = "HomeSerivce";

  public HomeSerivce() {
    mApi = new RetrofitFactory().getApi(HomeApi.class);

  }

  /**
   * 1请求商品列表
   * @return
   */
  public Observable<BaseResponse<List<GoodsInfo>>> getGoodsList() {
    return mApi.getGoodsList();
  }
  /**
   * 请求商品商品详情
   * @return
   */
  public Observable<BaseResponse<GoodsEntity>> getGoodsDetail(String id) {
//    http://dev.shopping.com/api/apiIndex/getGoodsDetail?id=10
    //Retrofit get 另外一种形式的请求
    String url = RetrofitFactory.BASEURLS_DOMAIN +"/api/apiIndex/getGoodsDetail?id=" + id /*+ "?page = "*/;
    return mApi.getGoodsDetail(url);
  }


  public interface HomeApi {
    //https://ke.4399tech.com/home/login/index
    //这个是后台入口
    //账号：test4399
    //密码：43994399
    //https://www.jianshu.com/p/cb2c375c9105 网络框架请求
    @GET("/api/apiIndex/getGoodsList")
    Observable<BaseResponse<List<GoodsInfo>>> getGoodsList();

    @GET
    Observable<BaseResponse<GoodsEntity>> getGoodsDetail(@Url String url);
  }

}
